#!/usr/bin/env bash

set -euox pipefail

BUILD_DIR=build_term

function clone() {
	dir=$1
	origin=$2
	upstream=$3
	git clone ${origin} ${dir}
	(
		cd ${dir}
		git remote add upstream ${upstream}
		git fetch upstream master
		git rebase upstream/master
	)
}

mkdir arkcompiler; cd arkcompiler

clone runtime_core \
	git@gitee.com:${GITEE_USER}/arkcompiler_runtime_core.git \
	https://gitee.com/openharmony/arkcompiler_runtime_core.git

clone ets_frontend \
	git@gitee.com:${GITEE_USER}/arkcompiler_ets_frontend.git \
	https://gitee.com/openharmony/arkcompiler_ets_frontend.git

( cd runtime_core/static_core/tools; ln -s ../../../ets_frontend/ets2panda es2panda )


cd runtime_core/static_core/plugins

clone ecmascript \
	git@gitee.com:${GITEE_USER}/arkcompiler_ets_runtime.git \
	https://gitee.com/openharmony-sig/arkcompiler_ets_runtime.git

cd ..

mkdir "${BUILD_DIR}"; cd "${BUILD_DIR}"

cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=../cmake/toolchain/host_clang_14.cmake ..
cmake --build .
#cmake --build . -t tests_full
